package service;

import mapper.StudentMapper;
import mapper.UserMapper;
import model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import util.Page;

import java.util.HashMap;
import java.util.List;

@Service

@Transactional
public class UserService {

    @Autowired

    private UserMapper userMapper;

    public User check_login(String username,String password){
        return this.userMapper.findUserByNameAndPassword(username,password);
    }



    public Page<play_list> findByPage(int currentPage, HashMap<String, Object> params) {

        HashMap<String, Object> map = new HashMap<String, Object>();

        Page<play_list> page = new Page<play_list>();

        //封装当前页数

        page.setCurrPage(currentPage);

        //每页显示的数据

        int pageSize = 4;//当前总共是9条，那么可以计算得到3页数据

        page.setPageSize(pageSize);

        //封装带条件查询的总记录数

        int totalCount = userMapper.selectCount(params);

        page.setTotalCount(totalCount);

        //封装总页数

        Integer totalcount = totalCount;

        //计算页数，如果整除，那么直接返回冒号左边的值，否则还需要加1

        Integer num = totalcount%pageSize==0? totalcount / pageSize: totalcount / pageSize+1;

        page.setTotalPage(num.intValue());//转换为整数

        map.put("start", (currentPage - 1) * pageSize);//起始的记录值

        map.put("size", page.getPageSize());//获取每个页面的pageSize

       // map.put("code",params.get("code"));

        map.put("username_homer",params.get("username_homer"));

        map.put("username_visiter",params.get("username_visiter"));

       // map.put("gender",params.get("gender"));



        //  map.put("查询条件参数",查询值)   如果后面要做带查询条件的分页，可以在这里添加查询参数，而查询条件参数可以在当前findByPage的方法里加一个参数

        List<play_list> list = userMapper.findByPage(map);

        page.setList(list);

        return page;

    }




    public List<game_list>get_game_lists(){


        return this.userMapper.get_game_lists();


    }


    public void new_apply(game_list game_list){

         this.userMapper.new_apply(game_list);
    }


    public game_list find_list_by_name_state(String player,int play_state) {
        return this.userMapper.find_list_by_name_state(player,play_state);

    }

    public void insert_play_list(play_list play_list){
        userMapper.insert_play_list(play_list);
    }


    public void update_play_list(play_list play_list){
        userMapper.update_play_list(play_list);
    }




    public void delete(int id){

        this.userMapper.delete(id);

    }


    public play_list find_play_list_ById(int id) {

        return this.userMapper.find_play_list_ById(id);

    }



    public void visiter_login(play_list play_list){

        this.userMapper.visiter_login(play_list);

    }


    public void insert_home_list(home_list home_list){


        this.userMapper.insert_home_list(home_list);
    }


    public List<home_list> find_game_list_ByName(String username){

         return userMapper.find_game_list_ByName(username);

    }

    public void change_home_list_state(home_list home_list){
        userMapper.change_home_list_state(home_list);


    }


    public home_list find_home_list_byId(int id){
        return userMapper.find_home_list_byId(id);
    }



    public home_list find_home_list_by_visiter_state(String visiter,int home_state){
        return userMapper.find_home_list_by_visiter_state(visiter,home_state);
    }




    public void insert_follower_list(follower_list follower_list){
        this.userMapper.insert_follower_list(follower_list);

    }



    public void insert_fan_list(fan_list fan_list){

        this.userMapper.insert_fan_list(fan_list);

    }



    public List<follower_list> find_follow_list_byName(String username){
        return userMapper.find_follow_list_byName(username);


    }


    public List<fan_list> find_fan_list_byName(String username){
        return userMapper.find_fan_list_byName(username);


    }

    public void not_follow(follower_list follower_list){
        userMapper.not_follow(follower_list);
    }

    public void not_fan(fan_list fan_list){
        userMapper.not_fan(fan_list);
    }

    public void insert_information(information information){
        userMapper.insert_information(information);
    }




    public List<information> find_information_byName(String username){
       return userMapper.find_information_byName(username);
    }
}
